package com.interest.base.utils;

import java.security.SecureRandom;
import java.util.Random;

/**
 * Created by wangliang on 16-10-31.
 */
public class RandomUtils {

    public static String generRandomSolt(int len) {
        Random ranGen = new SecureRandom();
        byte[] aesKey = new byte[len];
        ranGen.nextBytes(aesKey);
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < aesKey.length; i++) {
            String hex = Integer.toHexString(0xff & aesKey[i]);
            if (hex.length() == 1)
                hexString.append('0');
            hexString.append(hex);
        }
        System.out.println(hexString);

        return hexString.toString();
    }

    public static void main(String[] args) {
        generRandomSolt(20);
    }
}
